package com.cn.test1.servlet;
import com.cn.test1.model.CompanyModel;
import com.cn.test1.model.NavModel;
import com.cn.test1.service.CompanyService;
import com.cn.test1.service.NavService;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//servlet层响应给前端

@WebServlet("/home")//访问地址
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //拿到导航信息
        NavService navService = new NavService();
        List<NavModel> navModelList = navService.getNavModelList();//拿到导航信息
        req.setAttribute("navModelList",navModelList);//传递导航栏信息
        List<NavModel> navModelListTwo = navService.getNavModelListTwo();//拿到二级导航信息
        req.setAttribute("navModelListTwo",navModelListTwo);//传递二级导航信息

//        System.out.println(navModelList);

//拿到公司基本信息
        CompanyService companyService = new CompanyService();
        CompanyModel companyModel = companyService.getCompanyModel();

        List<CompanyModel> companyModelNavImg = companyService.getCompanyModelNavImg();
        req.setAttribute("companyModelNavImg",companyModelNavImg);//精品案例的图片文本信息

        req.setAttribute("companyModel",companyModel);//传公司基本信息
        req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);//页面转发，转发数据
        super.doGet(req, resp);
    }
}
